package com.hulizuofang.wol.chat.client.view;

import java.util.Set;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
import com.hulizuofang.wol.chat.client.gin.ClientI18nMessages;
import com.hulizuofang.wol.chat.client.presenter.WhoisOnlinePagePresenter.PageView;
import com.hulizuofang.wol.chat.client.ui.chat.WhoisOnlinePanel;
import com.hulizuofang.wol.chat.client.ui.user.ChatUser;
import com.hulizuofang.wol.chat.client.ui.user.ChatUserPanel;

public class WhoisOnlinePageViewImpl extends ViewImpl implements PageView {
	private AbsolutePanel container;
	private final WhoisOnlinePanel whoisOnlinePanel;
	private SimplePanel displayLogin;

	@Inject
	public WhoisOnlinePageViewImpl(ClientI18nMessages i18n, WhoisOnlinePanel whoisOnlinePanel) {
		this.whoisOnlinePanel = whoisOnlinePanel;
		container = new AbsolutePanel();
		displayLogin = new SimplePanel();
		container.add(displayLogin);
		container.add(whoisOnlinePanel);
	}

	@Override
	public Widget asWidget() {
		return container;
	}

	@Override
	public void refreshOnlineUser(Set<ChatUser> users) {
		whoisOnlinePanel.refreshOnlineUser(users);
	}

	@Override
	public void showUser(ChatUser user) {
		displayLogin.setWidget(new ChatUserPanel(user));
	}
}
